package fr.utbm.tx52;

import fr.utbm.tx52.contactsManagement.ContactList;
import fr.utbm.tx52.dataManagement.DataManager;
import fr.utbm.tx52.galerie.Galerie;
import fr.utbm.tx52.photo.Photo;
import fr.utbm.tx52.reception.PullService;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;


/**
 * Activitée principale
 *
 */
public class TX52 extends Activity {
    
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        /*
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        if (prefs.getBoolean("minimalmode", false)) {
        	Toast.makeText(getApplicationContext(), "Mode simplifié", Toast.LENGTH_LONG).show();
        } else {
        	Toast.makeText(getApplicationContext(), "Mode complet", Toast.LENGTH_LONG).show();
        }
        */
        
        DataManager.createApplicationDir();
        DataManager.fixUserPhoneNumber(this);
        
        
        // starting pull receving service, only once
        if ( PullService.getInstance() == null) {
        	startService(new Intent(TX52.this, PullService.class));
        }
        
        // prendre une photo
        final Button button_photo = (Button) findViewById(R.id.btn_photo);
        button_photo.setOnClickListener(new OnClickListener() {
        	public void onClick(View v) {
        		Intent i = new Intent();
        		i.setClass(getApplicationContext(), Photo.class);
        		startActivity(i);
        	}
        });
        
        
        
        // galerie de photo pour partager plusieurs en même temps
        final Button galerie = (Button) findViewById(R.id.btn_galerie);
        galerie.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
            	Log.i("-------------------------Launch galerie", "-----------------------------------------------------------------------");
            	Intent i = new Intent();
            	i.setClass(getApplicationContext(), Galerie.class);
        		startActivity(i);	
            }
        });
        
        
        
        // contacts management
        final Button manageContacts = (Button) findViewById(R.id.btn_contact);
        manageContacts.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
            	Log.i("-------------------------Launch contactList", "-----------------------------------------------------------------------");
            	Intent i = new Intent();
            	i.setClass(getApplicationContext(), ContactList.class);
        		startActivity(i);	
            }
        });
        
        
        // quit application
        final Button stop = (Button) findViewById(R.id.btn_quit);
        stop.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
            	finish();	
            }
        });
        
        
        // Test
        /*
        final Button testBtn = (Button) findViewById(R.id.btn_test);
        testBtn.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
  
            	Log.i("-------------------------Launch test", "-----------------------------------------------------------------------");
            	Intent i = new Intent();
            	i.setClass(getApplicationContext(), CommentAdder.class);
            	i.putExtra("photopath", "/sdcard/dcim/Camera/1304271416984.jpg");
        		startActivity(i);	
        		
            }

        });
        */
        
    }
    
    
    @Override
    /**
     * Création du menu qui permet d'ajouter un contact
     */
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.mainmenu, menu);
        return true;
    }
    
    /**
     * Sélection d'un item du menu
     */
    public boolean onOptionsItemSelected(MenuItem item) {
    	
    	switch (item.getItemId()) {  
    	case R.id.editpref :
    		Intent myIntent = new Intent(getApplicationContext(), Preferences.class);
            startActivityForResult(myIntent, 0);
    		return true;
    	}  
    	
    	return false;
    }
    
    
}

